/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 data_lock.h

	$Header: /heroes4/data_lock.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( DATA_LOCK_H_INCLUDED )
#define DATA_LOCK_H_INCLUDED

#include "owned_ptr.h"
// ------------------------------------------------------------------
// critical section wrapper class.  Atomic locking and unlocking.
// actual data is not in header to avoid use of windows.h
// ------------------------------------------------------------------
class t_data_lock
{
public:
	t_data_lock();
	~t_data_lock();

	void lock();
	void unlock();
protected:
	struct t_data;

	t_owned_ptr<t_data> m_lock;
};

// ------------------------------------------------------------------
// helper class for t_data_lock - locks on construct, unlocks on destruct
// ------------------------------------------------------------------
class t_data_locker
{
public:
	t_data_locker( t_data_lock& lock );
	~t_data_locker();
protected:
	t_data_lock& m_lock;
};

inline t_data_locker::t_data_locker( t_data_lock& lock ) : m_lock( lock )
{
	m_lock.lock();
}

inline t_data_locker::~t_data_locker()
{
	m_lock.unlock();
}



#endif // DATA_LOCK_H_INCLUDED